Post Convert Text To Speech
Welcome to the magic of turning words into a voice that speaks to the world! Imagine having a story to tell, an announcement to make, or just the joy of hearing a robot say "Hello, this is a test." The Convert Text To Speech (TTS)
API endpoint is your gateway to achieving that and more.
Let’s dive into the details of how you can unleash this power.
Endpoint
Your journey begins here:
https://api.betatel.com/api/v1/tts
This endpoint transforms text into speech, bringing life to static words. Add your language preference and the text you wish to voice out—it’s that simple!
Headers
Every hero needs their tools, and in this case, it’s your headers:
Param | Value | Description |
---|---|---|
Content-type | application/json | Specifies the format of your payload. |
x-api-key | {{x-api-key}} | Your unique API key for secure access. |
x-user-id | {{x-user-id}} | Your user identifier for added security and tracking. |
Request Body
{"language":"en", "text":"Hello, this is a test."}
Param | Type | Required | Description |
---|---|---|---|
language | string | Yes | Language represents the language in which the text is written. |
text | string | Yes | Text is the text that we want to translate into speech. |
Code Snippets
Let’s get hands-on with some examples in different languages to see how easy it is to communicate with this endpoint. Choose your weapon of choice below!
- cUrl
- Python
- Node.js
- PHP
- Java
- C#
curl --location 'https://dev.api.betatel.com/api/v1/tts' \
--header 'x-user-id: 6757f3ffb5e62f0ce0e513a2' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ••••••' \
--data '{"language":"en", "text":"Hello, this is a test."}'
import http.client
import json
conn = http.client.HTTPSConnection("dev.api.betatel.com")
payload = json.dumps({
"language": "en",
"text": "Hello, this is a test."
})
headers = {
'x-user-id': '6757f3ffb5e62f0ce0e513a2',
'Content-Type': 'application/json',
'x-api-key': '••••••'
}
conn.request("POST", "/api/v1/tts", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
const axios = require('axios');
let data = JSON.stringify({
"language": "en",
"text": "Hello, this is a test."
});
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://dev.api.betatel.com/api/v1/tts',
headers: {
'x-user-id': '6757f3ffb5e62f0ce0e513a2',
'Content-Type': 'application/json',
'x-api-key': '••••••'
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://dev.api.betatel.com/api/v1/tts',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS =>'{"language":"en", "text":"Hello, this is a test."}',
CURLOPT_HTTPHEADER => array(
'x-user-id: 6757f3ffb5e62f0ce0e513a2',
'Content-Type: application/json',
'x-api-key: ••••••'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://dev.api.betatel.com/api/v1/tts")
.header("x-user-id", "6757f3ffb5e62f0ce0e513a2")
.header("Content-Type", "application/json")
.header("x-api-key", "••••••")
.body("{\"language\":\"en\", \"text\":\"Hello, this is a test.\"}")
.asString();
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://dev.api.betatel.com/api/v1/tts");
request.Headers.Add("x-user-id", "6757f3ffb5e62f0ce0e513a2");
request.Headers.Add("x-api-key", "••••••");
var content = new StringContent("{\"language\":\"en\", \"text\":\"Hello, this is a test.\"}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
Response
Upon a successful request, the API returns a downloadable .wav file containing the generated speech. This file can be used immediately or stored for future playback.
Response Format:
Content Type
: audio/wavHeaders
:Content-Disposition
: attachment; filename="audio.wav"x-request-id
: A unique identifier to track the request for debugging or verification.Content-Length
: The size of the audio file in bytes.
HTTP/1.1 200 OK
Content-Type: audio/wav
Content-Disposition: attachment; filename="audio.wav"
Content-Length: 435678
x-request-id: 98f1b3d2-6e51-4c1d-bd4e-5f2a1c74fdae
Body
: Binary audio data (.wav format)
Congratulations
You’ve just unlocked the art of voice generation. The possibilities are endless—from chatbots to audiobooks, dynamic announcements to accessibility features. Let your creativity lead the way as you breathe life into your text!